<?php
/******************************
 * EQdkp
 * Copyright 2002-2003
 * Licensed under the GNU GPL.  See COPYING for full terms.
 * ------------------
 * install.php
 * Began: Sun January 5 2003
 * 
 * $Id: install.php 541 2008-05-20 06:56:16Z rspeicher $
 * 
 ******************************/

// Developer note: This is going to be fairly half-assed for now,
// because EQdkp's really not that complicated yet and its userbase
// is probably going to be fairly limited.   

// Check if it's already installed
// We're not dealing with upgrades yet, obviously
if ( @file_exists('config.php') )
{
    include('config.php');
}
if ( defined('EQDKP_INSTALLED') )
{
    header('Location: index.php');
}

// Check for phpinfo here...we don't want random
// people getting phpinfo() for this site after 
// EQdkp's already been installed
if ( (isset($HTTP_GET_VARS['mode'])) && ($HTTP_GET_VARS['mode'] == 'phpinfo') )
{
    phpinfo();
    exit;
}

error_reporting (E_ALL);

// Disable magic quotes and add slashes to global arrays
set_magic_quotes_runtime(0);
if ( !get_magic_quotes_gpc() )
{
    $_GET = slash_global_data($_GET);
    $_POST = slash_global_data($_POST);
}

define('EQDKP_INC', true);
$eqdkp_root_path = './';
include_once($eqdkp_root_path . 'includes/functions.php');

$defaults = array(
    'default_lang' => 'english',
    'default_style' => '1',
    'table_prefix' => 'eqdkp_',
    'dbal' => 'mysql');

$install_step = post_or_db('install_step', false);

// Display a simple table showing various PHP options/settings
// and whether or not this user's server meets the requirements.
if ( !$install_step )
{
    include($eqdkp_root_path . 'includes/eqdkp.php');
    include($eqdkp_root_path . 'language/english/lang_install.php');
    
    // EQdkp Version
    $this_version = '1.0.0';
    $current_version = get_eqdkp_version();
    $this_version = (( $this_version == $current_version ) ? '<span class="positive">' : '<span class="negative">') . $this_version . '</span>';
    
    // PHP Version
    $this_php_version = (( phpversion() >= '4.1.2' ) ? '<span class="positive">' : '<span class="negative">') . phpversion() . '</span>';
    $phpver = split_php_version(phpversion());
    
    $mysql = (( extension_loaded('mysql') ) ? '<span class="positive">Yes' : '<span class="negative">No') . '</span>';
    $zlib  = (( extension_loaded('zlib') ) ? '<span class="positive">Yes' : '<span class="negative">No') . '</span>';
    $mqgpc = !get_magic_quotes_runtime();
    
    $hidden_fields = '<input type="hidden" name="install_step" value="1" />';
    page_header('0', 'install.php', $hidden_fields);      
    ?>
    <tr>
      <td colspan="3" class="rowhead"><span class="largehead">EQdkp</span></td>
    </tr>
    <tr>
      <td width="34%" class="row2">Version:</td>
      <td width="33%" class="row1">Using: <?php echo $this_version; ?></td>
      <td width="33%" class="row2">Latest: <?php echo $current_version; ?></td>
    </tr>
    <tr>
      <td colspan="3" class="rowhead"><span class="largehead">PHP</span></td>
    </tr>
    <tr>
      <td colspan="3" class="row2"><a href="install.php?mode=phpinfo">View phpinfo()</a></td>
    </tr>                         
    <tr>
      <td width="34%" class="row2">Version:</td>
      <td width="33%" class="row1">Using: <?php echo $this_php_version; ?></td>
      <td width="33%" class="row2">Required: 4.1.2+</td>
    </tr>
    <tr>
      <td width="34%" class="row2">Major Version:</td>
      <td colspan="2" class="row1"><?php echo $phpver['major']; ?></td>
    </tr>
    <tr>
      <td width="34%" class="row2">Minor Version:</td>
      <td colspan="2" class="row1"><?php echo $phpver['minor']; ?></td>
    </tr>
    <tr>
      <td width="34%" class="row2">Version Classification:</td>
      <td colspan="2" class="row1"><?php echo $phpver['class']; ?></td>
    </tr>
    <tr>
      <td colspan="3" class="rowhead"><span class="largehead">PHP Module Capabilities</td>
    </tr>
    <tr>
      <td width="34%" class="row2">MySQL:</td>
      <td width="33%" class="row1">Supported: <?php echo $mysql; ?></td>
      <td width="33%" class="row2">Required: Yes</td>
    </tr>
    <tr>
      <td width="34%" class="row2">Zlib:</td>
      <td width="33%" class="row1">Supported: <?php echo $zlib; ?></td>
      <td width="33%" class="row2">Required: No</td>
    </tr>
    <?php
    page_tail($lang['start_install'], 3, true);
    exit;
}
else
{
    $submit = ( isset($_POST['submit']) ) ? true : false;

    // Figure out field values
    $dbtype = post_or_db('dbtype', false);
    $default_lang = post_or_db('default_lang', true, $defaults);
    
    $dbhost = post_or_db('dbhost', false);
    $dbname = post_or_db('dbname', false);
    $dbuser = post_or_db('dbuser', false);
    $dbpass = post_or_db('dbpass', false);
    
    $table_prefix = post_or_db('table_prefix', true, $defaults);
    
    $username = post_or_db('username', false);
    $user_password1 = post_or_db('user_password1', false);
    $user_password2 = post_or_db('user_password2', false);
    
    $server_name = post_or_db('server_name', false);
    $server_port = post_or_db('server_port', false);
    $server_path = post_or_db('server_path', false);
    $admin_email = post_or_db('admin_email', false);
        
    include($eqdkp_root_path . 'includes/eqdkp.php');
    include($eqdkp_root_path . 'language/' . $default_lang . '/lang_install.php');
    
    $available_dbals = array(
        'mysql' => array(
            'label' => 'MySQL 3.x',
            'structure' => 'mysql',
            'comments' => 'remove_remarks',
            'delim' => ';',
            'delim_basic' => ';')
    );
    
    //
    // Writing/sending the config file
    //
    // Step 1
    if ( ((empty($install_step)) || ($user_password1 != $user_password2) || (empty($user_password1)) || ($dbhost == '')) && (!defined('EQDKP_INSTALLED')) )
    {
        // Guess the server settings
        $server_name = ( !empty($_SERVER['HTTP_HOST']) ) ? $_SERVER['HTTP_HOST'] : $_ENV['HTTP_HOST'];
        if ( (!empty($_SERVER['SERVER_PORT'])) || (!empty($_ENV['SERVER_PORT'])) )
        {
            $server_port = ( !empty($_SERVER['SERVER_PORT']) ) ? $_SERVER['SERVER_PORT'] : $_ENV['SERVER_PORT'];
        }
        else
        {
            $server_port = '80';
        }
        $server_path = preg_replace('/install\.php/i', '', $_SERVER['PHP_SELF']);
        
        // Build Language drop-down
        $lang_dropdown = '';
        if ( $dir = @opendir($eqdkp_root_path . 'language/') )
        {
            $lang_dropdown = '<select name="default_lang" class="input">';
            while ( $file = @readdir($dir) )
            {
                if ( (!is_file($eqdkp_root_path . 'language/' . $file)) && (!is_link($eqdkp_root_path . 'language/' . $file)) && ($file != '.') && ($file != '..') && ($file != 'CVS') )
                {
                    $selected = ( $defaults['default_lang'] == $file ) ? ' selected="selected"' : '';
                    $lang_dropdown .= '<option value="' . $file . '"' . $selected . '>' . ucfirst($file) . '</option>';
                }
            }
            $lang_dropdown .= '</select>';
        }
        
        // Build Database drop-down
        $dbal_dropdown = '<select name="dbtype" class="input">';
        foreach ( $available_dbals as $type => $options )
        {
            $selected = ( $defaults['dbal'] == $type ) ? ' selected="selected"' : '';
            
            $dbal_dropdown .= '<option value="' . $type . '"' . $selected . '>' . $options['label'] . '</option>';
        }
        $dbal_dropdown .= '</select>';
        
        // Page output
        $hidden_fields = '<input type="hidden" name="install_step" value="1" />';
        page_header('1', 'install.php', $hidden_fields);
        ?>
        <tr>
          <td colspan="2" class="rowhead" align="center"><?php echo $lang['basic_configuration']; ?></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['default_lang']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<?php echo $lang_dropdown; ?></td>
        </tr>
        <tr>
          <td colspan="2" class="rowhead" align="center"><?php echo $lang['database_configuration']; ?></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['dbtype']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<?php echo $dbal_dropdown; ?></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['dbhost']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="text" name="dbhost" size="25" value="<?php echo $dbhost; ?>" class="input" /></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['dbname']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="text" name="dbname" size="25" value="<?php echo $dbname; ?>" class="input" /></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['dbuser']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="text" name="dbuser" size="25" value="<?php echo $dbuser; ?>" class="input" /></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['dbpass']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="password" name="dbpass" size="25" value="<?php echo $dbpass; ?>" class="input" /></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['table_prefix']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="text" name="table_prefix" size="25" value="<?php echo $table_prefix; ?>" class="input" /></td>
        </tr>
        <tr>
          <td colspan="2" class="rowhead" align="center"><?php echo $lang['server_configuration']; ?></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['server_name']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="text" name="server_name" size="25" value="<?php echo $server_name; ?>" class="input" /></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['server_port']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="text" name="server_port" size="25" value="<?php echo $server_port; ?>" class="input" /></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['server_path']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="text" name="server_path" size="25" value="<?php echo $server_path; ?>" class="input" /></td>
        </tr>
        <tr>
          <td colspan="2" class="rowhead" align="center"><?php echo $lang['administrator_configuration']; ?></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['username']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="text" name="username" size="25" value="<?php echo $username; ?>" class="input" /></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['user_password']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="password" name="user_password1" size="25" value="<?php echo $user_password1; ?>" class="input" /></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['user_password_confirm']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="password" name="user_password2" size="25" value="<?php echo $user_password2; ?>" class="input" /></td>
        </tr>
        <tr>
          <td width="40%" class="row2" align="right"><?php echo $lang['user_email']; ?>:&nbsp;</td>
          <td width="60%" class="row1">&nbsp;<input type="text" name="user_email" size="25" value="" class="input" /></td>
        </tr>
        <?php   
        page_tail($lang['start_install']);      
        exit;
        
    } // Step 1
    
    // Create/populate the DB
    // This isn't going to be very complicated just yet since
    // we're only dealing with MySQL 3.x at this point
    else
    {
        if ( isset($dbtype) )
        {
            define('DEBUG', 0);
            
            include($eqdkp_root_path . 'dbal/' . $dbtype . '.php');
            $db = new SQL_DB($dbhost, $dbname, $dbuser, $dbpass, false);
            
            $db_structure = $eqdkp_root_path . 'dbal/structure/' . $dbtype . '_structure.sql';
            $db_data      = $eqdkp_root_path . 'dbal/structure/' . $dbtype . '_data.sql';
            
            $remove_remarks = $available_dbals[$dbtype]['comments'];
            $delimiter = $available_dbals[$dbtype]['delim'];
            $delimiter_basic = $available_dbals[$dbtype]['delim_basic'];
            
            if ( $install_step == 1 )
            {
                $sql = @fread(@fopen($db_structure, 'r'), @filesize($db_structure));
                $sql = preg_replace('/eqdkp_/is', $table_prefix, $sql);
                
                $sql = $remove_remarks($sql);
                $sql = parse_sql($sql, $delimiter);
                
                $sql_count = count($sql);
                $output_message = '';
                for ( $i = 0; $i < $sql_count; $i++ )
                {   
                    $db->query($sql[$i]);
                }
                
                // Tables have been created, insert the data we need to
                $sql = @fread(@fopen($db_data, 'r'), @filesize($db_data));
                $sql = preg_replace('/eqdkp_/is', $table_prefix, $sql);
                
                $sql = $remove_remarks($sql);
                $sql = parse_sql($sql, $delimiter_basic);
                
                $sql_count = count($sql);
                for ( $i = 0; $i < $sql_count; $i++ )
                {
                    $db->query($sql[$i]);
                }
                
                // Tables created, basic config, style, auth settings have been entered
                // Create their admin account and update config settings
                $user_password_md5 = md5($user_password1);
                
                define('CONFIG_TABLE', $table_prefix . 'config');
                define('USERS_TABLE',  $table_prefix . 'users');
                
                $sql = 'UPDATE ' . USERS_TABLE . "
                        SET username='".$username."', user_password='".$user_password_md5."', user_lang='".$default_lang."', 
                            user_email='".$user_email."', user_active='1'";
                $db->query($sql);
                
                $sql = 'UPDATE ' . CONFIG_TABLE . "
                        SET config_value='".$server_name."'
                        WHERE config_name='server_name'";
                $db->query($sql);
                
                $sql = 'UPDATE ' . CONFIG_TABLE . "
                        SET config_value='".$server_port."'
                        WHERE config_name='server_port'";
                $db->query($sql);
                
                $sql = 'UPDATE ' . CONFIG_TABLE . "
                        SET config_value='".$server_path."'
                        WHERE config_name='server_path'";
                $db->query($sql);
                
                $sql = 'UPDATE ' . CONFIG_TABLE . "
                        SET config_value='".$default_lang."'
                        WHERE config_name='default_lang'";
                $db->query($sql);
                
                $sql = 'UPDATE ' . CONFIG_TABLE . "
                        SET config_value='".$user_email."'
                        WHERE config_name='admin_email'";
                $db->query($sql);
                
                //
                // Attempt to write config data to config.php
                //
                $config_file  = '';
                $config_file .= '<?php' . "\n";
                $config_file .= '$dbtype = "' . $dbtype . '";' . "\n\n";
                $config_file .= '$dbhost = "' . $dbhost . '";' . "\n";
                $config_file .= '$dbname = "' . $dbname . '";' . "\n";
                $config_file .= '$dbuser = "' . $dbuser . '";' . "\n";
                $config_file .= '$dbpass = "' . $dbpass . '";' . "\n\n";
                $config_file .= '$table_prefix = "' . $table_prefix . '";' . "\n\n";
                $config_file .= 'define(\'EQDKP_INSTALLED\', true);' . "\n";
                $config_file .= '?>';
                
                // Set our permissions to execute-only
                @umask(0111);
                
                if ( !($fp = @fopen('config.php', 'w')) )
                {
                    // Can't open the file with write permission
                    echo 'Can\'t open the config file for writing.  Paste the following into config.php and save the file.';
                    echo '<pre>';
                    echo htmlspecialchars($config_file);
                    echo '</pre><br />After config.php is set up click <a href="index.php">here</a>';
                    die();
                }
                $result = @fputs($fp, $config_file, strlen($config_file));
                @fclose($fp);
                header('Location: login.php');
            }
        }
    }
}
 
/**
* Applies addslashes() to the provided data
*
* @param $data Array of data or a single string
* @return mixed Array or string of data
*/
function slash_global_data($data)
{
    if ( is_array($data) )
    {
        foreach ( $data as $k => $v )
        {
            $data[$k] = ( is_array($v) ) ? slash_global_data($v) : htmlspecialchars(addslashes($v));
        }
    }
    return $data;
}                                    

function page_header($step, $f_action, $hidden_fields='')
{
    global $lang;
    
    echo '<?xml version="1.0" encoding="iso-8859-1"?>';
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>                          
    
    <title>EQdkp Installation</title>
    <style type="text/css">
    <!--
    body {
        font-family: Verdana, Tahoma, Arial;
        font-size: 11px;
        color: #000000;    
        background-color: #212042;
    }
    table {
        border-top: 1px;
        border-right: 1px;
        border-bottom: 1px;
        border-left: 1px;
        border-color: #7B819A;
        border-style: solid;
    }
    table.borderless {
        border-style: none;
    }
    td {
        font-size: 11px;
    }
    a:link,a:active,a:visited {
        color: #31308C;
        text-decoration: underline;
    }
    a:hover {
        color: #000084;
        text-decoration: underline;
    }
    .rowhead {
        font-weight: bold;
        color: #CECFEF;
        background-color: #424563;
        white-space: nowrap;
    }
    .row1 {
        background-color: #EFEFEF;
    }
    .row2 {
        background-color: #FFFFFF;
    }
    .rowfoot {
        color: #CECFEF;
        text-align: right;
        background-color: #424563;
        white-space: nowrap;
    }
    .positive {
        color: #008800;
    }
    .negative {
        color: #F80000;
    }
    .small {
        font-size: 10px;
    }
    .copy {
        font-size: 10px;
        color: #CECFEF;
    }
    .input {
        font-family: Verdana, Tahoma, Arial;
        font-size: 10px;
        color: #000000;
        background-color: #FFFFFF;
        border-top: 1px;
        border-right: 1px;
        border-bottom: 1px;
        border-left: 1px;
        border-color: #000000;
        border-style: solid;
    }
    input.mainoption {
        font-family: Verdana, Tahoma, Arial;
        font-size: 10px;
        font-weight: bold;
        color: #CECFEF;
        background-color: #424563;
        border-top: 1px;
        border-right: 1px;
        border-bottom: 1px;
        border-left: 1px;
        border-color: #CECFEF;
        border-style: solid;
    }
    input.liteoption {
        font-family: Verdana, Tahoma, Arial;
        font-size: 10px;
        font-weight: normal;
        color: #CECFEF;
        background-color: #424563;
        border-top: 1px;
        border-right: 1px;
        border-bottom: 1px;
        border-left: 1px;
        border-color: #CECFEF;
        border-style: solid;
    }
    .maintitle {
        font-size: 18px;
        font-weight: bold;
        color: #CECFEF;
    }
    .subtitle {
        font-size: 12px;
        color: #CECFEF;
    }
    .largehead
    {         
        font-size: 16px;
        color: #CECFEF;
        font-weight: bold;
    }
    -->
    </style>
    </head>
    
    <body>
    
    <table width="100%" border="0" cellspacing="1" cellpadding="2" class="borderless">
      <tr>
        <td width="201" nowrap="nowrap"><img src="./templates/default/images/logo.gif" alt="Logo" /><br /></td>
        <td width="100%">
          <center><span class="maintitle">EQdkp Installation</span></center>
        </td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2" class="copy"><?php echo $lang['note_step'.$step]; ?></td>
      </tr>
    </table>
    <br />    
    <form method="post" action="<?php echo $f_action; ?>" name="post">
    <?php echo $hidden_fields ?>
    <table width="100%" border="0" cellspacing="1" cellpadding="2">
    <?php
}

function page_tail($l_submit, $colspan = 2, $show_submit = true)
{
    if ( $show_submit )
    {
    ?>
    <tr>
      <td colspan="<?php echo $colspan; ?>" class="rowhead" align="center"><input type="submit" name="submit" value="<?php echo $l_submit; ?>" class="mainoption" /></td>
    </tr>
    <?php
    }
    ?>
    </table>
    </form>
    <br />
    <center><span class="copy">Powered by EQdkp<br />&copy; 2002-2003 The EQdkp Project Team</span></center>
    <br />
    </body>
    </html>
    <?php
}

function remove_remarks($sql)
{
    if ( $sql == '' )
    {
        die('Could not obtain SQL structure/data');
    }
    $lines = explode("\n", $sql);
    //unset($sql);
        
    $linecount = count($lines);
    $return = '';
    
    for ( $i = 0; $i < $linecount; $i++ )
    {
        // Only parse this if there's something on this line, and we're not on the last line
        if ( strlen($lines[$i]) > 0)
        {
            // If '#' is the first character, strip the line
            $return .= ( $lines[$i][0] != '#' ) ? $lines[$i] . "\n" : "\n";
            $lines[$i] = '';
        }
    }
    unset($lines);
    
    return $return;
}

function parse_sql($sql, $delimiter)
{
    if ( $sql == '' )
    {
        die('Could not obtain SQL structure/data');
    }
    $statements = explode($delimiter, $sql);
    unset($sql);
    
    $linecount = count($statements);
    for ( $i = 0; $i < $linecount; $i++ )
    {
        if ( ($i != $linecount - 1) || (strlen($statements[$i]) > 0) )
        {
            $statements[$i] = trim($statements[$i]);
            $statements[$i] = str_replace("\r\n", '', $statements[$i]) . "\n";
            
            // Replace spaces greater than one with one space
            $statements[$i] = preg_replace('/[[:space:]]{2,}/', ' ', $statements[$i]);
            
            $return[] = trim($statements[$i]);
        }
    }
    unset($statements);
    
    return $return;
}

function get_eqdkp_version()
{
    // Try and get the latest EQdkp version from EQdkp.com
    $sh = fsockopen('eqdkp.com', 80, $errno, $error);
    if ( !$sh )
    {
        return 'Connection failed.';
    }
    
    fputs($sh, "GET /version.php HTTP/1.1\r\nHost: eqdkp.com\r\nConnection: close\r\n\r\n");
    while ( !feof($sh) )
    {
        $content = fgets($sh, 512);
        if ( preg_match('/<version>(.*)<\/version>/', $content, $version) )
        {
            return $version[1];
        }
    }
    fclose($sh);
    
    return 'Unknown';
}

function split_php_version($version)
{
    // Based on Horde framework, www.horde.org
    // Pick off major version, and lower-case the rest.
    if ( (strlen($version) > 3) && ($version[1] == '.') )
    {
        $phpver['major'] = substr($version, 0, 3);
        $version = substr(strtolower($version), 3);
    }
    else
    {
        $phpver['major'] = $version;
        $phpver['class'] = 'unknown';
        
        return $phpver;
    }
    
    if ( $version[0] == '.')
    {
        $version = substr($version, 1);
    }
    
    // Now determine if this is x.xb or x.xRC; if so, there is no minor,
    // the rest is the subminor, and class is set to 'beta'.
    $s = strspn($version, '0123456789');
    if ( $s == 0 )
    {
        $phpver['subminor'] = $version;
        $phpver['class'] = 'beta';
        
        return $phpver;
    }
    // Otherwise this is a non-beta; the numeric part is the minor,
    // the rest is either a classification (dev, cvs) or a subminor
    // version (rc<x>, pl<x>).
    $phpver['minor'] = substr($version, 0, $s);
    if ( (strlen($version) > $s) && (($version[$s] == '.') || ($version[$s] == '-')) )
    {
        $s++;
    }
    
    $phpver['subminor'] = substr($version, $s);
    if ( ($phpver['subminor'] == 'cvs') || ($phpver['subminor'] == 'dev') || (substr($phpver['subminor'], 0, 2) == 'rc') )
    {
        unset($phpver['subminor']);
        $phpver['class'] = 'dev';
    }
    else
    {
        if ( !$phpver['subminor'])
        {
            unset($phpver['subminor']);
        }
        $phpver['class'] = 'release';
    }
    
    return $phpver;
}
?>
